#include <QApplication>
#include <QObject>
#include <QTextCodec>
#include <QDir>
#include <QProcess>
#include <QDebug>

#include <core_system/qls_core_system.h>
#include <languages_manager/qls_languages_manager.h>
#include <log/qls_log.h>
#include <login_appfwk/qls_login_appfwk.h>
#include <settings/qls_settings.h>

int main(int argc, char *argv[])
{
    qputenv("QT_ENABLE_HIGHDPI_SCALING", "1");
#if QT_VERSION >= 0x050E02 //定义到Qt5.14.2
    QGuiApplication::setHighDpiScaleFactorRoundingPolicy(
        Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
#endif

    QApplication a(argc, argv);

    // 解析配置 --workspace 默认 ../
    if (QProcessEnvironment::systemEnvironment().contains("HOME")) {
        QLsSettings::setWorkSpace(QDir::cleanPath(
            QProcessEnvironment::systemEnvironment().value("HOME") +
            "/qlpmsp/"));
    } else {
        QLsSettings::setWorkSpace(QLsSettings::getInstallPath());
    }

    /* 加载语言包 */
    QLsLanguagesManager::GetInstance();

    /* 设置日志文件 */
    QLsLog::GetInstance().SetLogPath("");

    QLsLoginAppfwk l;
    QLsCoreSystem w;

    QObject::connect(&l, &QLsLoginAppfwk::sigLogin, &w,
                     &QLsCoreSystem::slotLogin);
    l.show();

    return a.exec();
}
